#include <climits>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int n = 0;
	cin >> n;
	vector<int> arr(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> arr[i];
	}
    int ret = arr[0];
    for (int i = 1; i < arr.size(); i++) 
    {
        arr[i] += max(arr[i - 1], 0);
        ret = max(ret, arr[i]);
    }
    /*
	int ret = -INT_MAX, sum = 0;
    for (int i = 0; i < n; ++i)
	{
		for (int j = i; j < n; ++j)
		{
			sum += arr[j];
			ret = max(ret, sum);
		}
		sum = 0;
	}
    */
	cout << ret;
	return 0;
}